package org.noote.libs.computervision.function;

public class Kernel {

	static public short [] do3x3_i8(float fKernel[], float fDivider, float fDisplace, int iWidth, int iHeight, short pIn[])
	{
		short [] pOut = new short[pIn.length];
		
		// set blank values
		for(int i=0; i<pOut.length; i++) pOut[i]=0;
		
		int idx;
		float fe;
		for(int y=1; y<iHeight-1; y++)
		{
			for(int x=1; x<iWidth-1; x++)
			{
				idx=y*iWidth+x;
				
				fe = (
						pIn[idx-iWidth-1]*fKernel[0]
					+	pIn[idx-iWidth]*fKernel[1]
					+	pIn[idx-iWidth+1]*fKernel[2]
					+	pIn[idx-1]*fKernel[3]
					+	pIn[idx]*fKernel[4]
					+	pIn[idx+1]*fKernel[5]
					+	pIn[idx+iWidth-1]*fKernel[6]
					+	pIn[idx+iWidth]*fKernel[7]
					+	pIn[idx+iWidth+1]*fKernel[8]
						)*fDivider + fDisplace;
				
				if(fe>255.0f) fe=255.0f;
				else if (fe<0.0f) fe=0.0f;
				
				pOut[idx] = (short)fe;
			}			
		}
		
		return pOut;
	}
}
